#ifndef __FS_STRUCT_H__
#define __FS_STRUCT_H__

#define NR_OPEN_DEFAULT	(0X20)

/*
**	、对于每一类文件系统都只会提供一套file_operation函数
*/
struct file_operation{
	struct module *owner;
	int (*open)(struct inode *,struct file *);
	int (*mmap)(struct file *,struct vm_area_struct *);
	size_t (*read)(struct file *,char *,size_t,loff_t *);
	size_t (*write)(struct file *,const char *,size_t,loff_t *);
	loff_t (*llseek)(struct file *,size_t,loff_t *);
	int (*ioctl)(struct inode *,struct file *,unsigned int,unsigned long);
	int (*flush)(struct file *);
};

/*
**	、无论是文件还是文件夹，都需要索引
*/
struct inode{
	char inode_type;//标识是文件还是文件夹
	struct list_head list;//简单一点设计，将文件的索引挂接到根文件的链表上
	int uid,gid;//该文件的uid和group id
	unsigned long i_time;//最后一次访问该文件的时间戳
	char name[32];//文件名
	unsigned long i_size;//文件的大小
	semplore_t i_sem;
	atomic_t icount;//当前还在持有该文件的计数
};



struct dentry{
	atomic_t d_count;
	struct inode *d_inode;//文件/文件夹索引节点，当要访问时候，就是根据索引节点进行查找
	struct dentry *d_par;
	struct list_head d_child;//子节点链表头
	unsigned long d_time;//创建时间
	unsigned char d_iname[32];//文件夹名字
	struct list_head d_list;//挂接到parent的list表
};

/*
**	dentry操作集合
*/
struct dentry_operations{
	int (*d_delete)(struct dentry *);//dlete directory
	void (*d_release)(struct dentry *);//close directory
	
};


struct fs_struct{
	atomic count;//fs count
	rwlock_t lock;//read and write lock
	int umask;//file umask
	struct dentry *root,*pwd,*altroot;//目录项的绝对root路径，当前用户路径和相对root路径的属性
	struct vfsmount *rootmnt,*pwdmnt,*altrootmnt;
};


struct files{
	struct dentry *dentry;//describe file information
	struct file_operation *fops;//read and write file or directory
};

/*
**	file information
*/
struct file_struct{
	struct files fd_array[NR_OPEN_DEFAULT];//当前路径下可能有多个文件
	rwlock_t file_lock;
	int max_fds;
	int max_fdset;
	int next_fd;
	struct file **fd;//指向最初的fd_array
	fd_set *close_on_exec;
	fd_set *open_fds;
};

struct task_struct{
	struct file_struct *file;//current used filesystem type
	struct fs_struct *fs;//lowlevel registered filesystem
};

#endif
//__FS_STRUCT_H__